using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public interface CatsTrigger : CatTrigger
{
	void onTrigger (int componentIndex);
}

public class CatsInvoker : AbstractCatInvoker<CatsTrigger>
{
	
	int componentIndex;
	
	public CatsInvoker (CatsTrigger catsInvoker, int componentIndex) : base(catsInvoker)
	{
		this.componentIndex = componentIndex;
	}
	
	override public void run ()
	{
		catTrigger.onTrigger (componentIndex);
	}
}

public abstract class UICats<T> : UICan<T>, CatsTrigger where T : Component
{
	
	override protected void initComponent ()
	{
		base.initComponent ();
		int count = componentSort.Count;
		for (int i = 0; i < count; i++) {
			T component = componentSort [i];
			UICat cat = component.gameObject.GetComponent<UICat> ();
			if (cat == null) {
				cat = component.gameObject.AddComponent<UICat> ();
			}
			
			cat.addCatInvoker (new CatsInvoker (this, i));
		}
	}
	
	virtual public void onTrigger (int componentIndex)
	{
		setActiveComponentIndex (componentIndex);
	}
}
